import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import { title } from '@/settings'

//需要把项目中的路由进行拆分
/**
 * 常量路由:不管什么角色都可以看到
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },


]
/**
 * 
 * 异步路由:不用的用户显示不同菜单不同的按钮
 */
export const asyncRoutes = [
  {
    path: '/product',
    component: Layout,
    name: 'Product',
    meta: { title: "商品管理", icon: 'el-icon-goods' },
    children: [
      {
        path: 'trademark',
        component: () => import('@/views/product/trademark'),
        name:"Trademark",
        meta: { title: '品牌管理' }
      },
      {
        path: 'attr',
        component: () => import('@/views/product/attr'),
        meta: { title: '属性管理' },
        name:"Attr"
      },
      {
        path: 'spu',
        component: () => import('@/views/product/spu'),
        meta: { title: 'Spu管理' },
        name:"Spu"
      },
      {
        path: 'sku',
        component: () => import('@/views/product/sku'),
        meta: { title: 'Sku管理' },
        name:"Sku"
      }
    ]
  },
  {
    name: 'Acl',
    path: '/acl',
    component: Layout,
    redirect: '/acl/user/list',
    meta: {
      title: '权限管理',
      icon: 'el-icon-lock'
    },
    children: [
      {
        name: 'User',
        path: 'user/list',
        component: () => import('@/views/acl/user/list'),
        meta: {
          title: '用户管理'
        }
      },
      {
        name: 'Role',
        path: 'role/list',
        component: () => import("@/views/acl/role/list"),
        meta: {
          title: '角色管理'
        }
      },
      {
        name: 'RoleAuth',
        path: 'role/auth/:id',
        component: () => import("@/views/acl/role/roleAuth"),
        meta: {
          activeMenu: '/acl/role/list',
          title: '角色授权'
        }
      },
      {
        name: 'Permission',
        path: 'permission/list',
        component: () => import('@/views/acl/permission/list'),
        meta: {
          title: "权限列表"
        }
      }
    ]
  },
]
//任意路由 当路径出现错误的时候
export const anyRoutes = [{ path: '*', redirect: '/404', hidden: true }]
const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
